<?php

namespace App\Http\Controllers\Api\Order;
use App\Http\Controllers\Api\User\ReBateController;
use App\Http\Controllers\ApiController;
use App\Http\Models\User\UserBaseModel;
use App\Models\Order;
use App\Models\RechargeOrder;
use Illuminate\Http\Request;

class RechargeOrderController extends ApiController
{
   public  function createRechargeOrder(Request $request)
   {
       $input = $request->all();
       if (empty($input['uid'])){
           return self::response(null,'-1','登录状态错误');
       }

       if (empty($input['total_amount'])){
           return self::response(Null,-2,'请输入充值金额');
       }

       $total_amount                    = $input['total_amount'];
       $uid                             = $input['uid'];
       $user                            = UserBaseModel::getUser($uid);

       if (empty($user)){
           return self::response(null,-4,'用户不存在');
       }
       if (!is_numeric($total_amount)||$total_amount<=0){
           return self::response(Null,-5,'充值金额错误');
       }

       if(empty($user['open_id'])){
           return self::response(null,self::UN_BIND_OPENID,'未绑定open_id');
       }

       $Id                            = RechargeOrder::addRechargeOrder($input,1);
       if ($Id<=0){
          return self::response(null,'-6','操作失败');
       }else{
          $order = RechargeOrder::find($Id);
          return  self::response(['order'=>$order],200);
       }
   }





}
